package Page.MainPage;

import Controller.MainController;
import Controller.User.UserType;
import Navigation.NavigationController;
import DataClass.Announcement;

import Page.LoginInterfacePage.LoginInterfacePage;
import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.stage.Modality;
import javafx.stage.Stage;

import java.util.List;

import static Controller.MainController.getUserType;


public class MainPageViewModel {
    ListProperty<Announcement> dataList1 = new SimpleListProperty<>(FXCollections.observableArrayList());
    ListProperty<Announcement> dataList2 = new SimpleListProperty<>(FXCollections.observableArrayList());
    ListProperty<Announcement> dataList3 = new SimpleListProperty<>(FXCollections.observableArrayList());

    public ListProperty<Announcement> dataListProperty1() {
        return dataList1;
    }
    public ListProperty<Announcement> dataListProperty2() {
        return dataList2;
    }
    public ListProperty<Announcement> dataListProperty3() {
        return dataList3;
    }

    public ObservableList<Announcement> getDataList1() {
        return dataList1.get();
    }
    public ObservableList<Announcement> getDataList2() {
        return dataList2.get();
    }
    public ObservableList<Announcement> getDataList3() {
        return dataList3.get();
    }

    public void setDataList1(ObservableList<Announcement> dataList) {
        this.dataList1.set(dataList);
    }
    public void setDataList2(ObservableList<Announcement> dataList) {
        this.dataList2.set(dataList);
    }
    public void setDataList3(ObservableList<Announcement> dataList) {
        this.dataList3.set(dataList);
    }

    public void setDataList1(List<Announcement> dataList) {
        setDataList1(FXCollections.observableArrayList(dataList));
    }
    public void setDataList2(List<Announcement> dataList) {
        setDataList2(FXCollections.observableArrayList(dataList));
    }
    public void setDataList3(List<Announcement> dataList) {
        setDataList3(FXCollections.observableArrayList(dataList));
    }

    private static StringProperty helloText = new SimpleStringProperty();

    public StringProperty getHelloProperty(){
        return helloText;
    }

    public static void updateHelloText(){
        String temp = "";
        UserType userType = getUserType();
        if (userType != null) {
            if (userType == UserType.TEACHER) {
                temp = "老师";
            } else if (userType == UserType.STUDENT) {
                temp = "同学";
            }else if(userType == UserType.MANAGER) {
                temp = "";      // 名字叫管理员，类型就只能为空了
            }
        } else {
            temp = "游客";
        }
        String temp2 = MainController.getCurrentUsrName();
        if(MainController.getCurrentUsrName()==null){
            temp2 = "";
        }
        MainPageViewModel.helloText.set("欢迎" + temp2 + temp + "访问北京理工大学网络攻防对抗技术研究所管理系统！");
    }
}
